package com.cyf.third.advertising;

import com.cyf.third.advertising.network.bean.AdvertisingReq;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

@Controller
@RestController
@RequestMapping(value = "/third/advertising")
@Api("广告对接")
public class AdvertisingHttpController {
    @Autowired
    private RestTemplate restTemplater;

    @ApiOperation(value = "调用广告第三方")
    @PostMapping(value = "/adver")
    public String switchParking(@RequestBody AdvertisingReq advertisingReq) {
        // 封装参数，千万不要替换为Map与HashMap，否则参数无法传递
        String url="http://api.parkingad.cn/api/ad/bid";
        MultiValueMap<String, Object> paramMap = new LinkedMultiValueMap<String, Object>();
        paramMap.add("accountId", advertisingReq.getAccountId());
        paramMap.add("requestId", advertisingReq.getRequestId());
        paramMap.add("data", advertisingReq.getData());
        paramMap.add("sign", advertisingReq.getSign());
        // 1、使用postForObject请求接口
        String result = restTemplater.postForObject(url, paramMap, String.class);

        return result;
    }

}
